<?php echo $this->Html->css('admin/admin_organisations_index'); ?>
<style>
    #accounts-table tbody td {
        cursor: pointer;
    }

    #accounts-table tbody tr.selected td {
        background-color: #347892 !important;
        color: #fff;
    }

    #accounts-table tbody tr.selected td .text-muted {
        color: #eee;
    }
</style>

<div class="" id="container">

    <div class="row">

        <div class='col-lg-4'>
            <section class='panel m-b-none'>
                <div class='panel-heading'>
                    <div class='row'>
                        <span class='col-lg-6'><p class='m-t-xs'><i class='fa fa-list'></i> Roles</p></span>
                        <span class='col-lg-6 text-right'>
                            <button type="button" id='add_role' class='btn btn-info btn-sm'><i class='fa fa-plus'></i> Add Role</button>
                        </span>
                    </div>
                </div>
                <div class='panel-body'>
                    <div id='roles_list' class="list-group bg-white">
                        <?php
                        $count = 1;
                        foreach ($roles as $role) {
                            ?>
                            <a href="#" class="list-group-item" data-id='<?php echo $role['OrganisationRole']['id']; ?>'>
                                <i class="fa fa-chevron-right"></i>

                                    <!--<input type="checkbox" class="m-r" name="" value="<?php echo $role['OrganisationRole']['id']; ?>" />-->
                                <?php echo $role['OrganisationRole']['name']; ?>
                            </a>
                            <?php
                            $count++;
                        }
                        ?>
                    </div>
                </div>
            </section>
        </div>

        <div class='col-lg-8' id='role_form_area'>
            <section class='panel m-b-none'>
                <div class='panel-heading'>
                    <div class='row'>
                        <span class='col-lg-9'>
                            <div class='m-t-xs'><i class='fa fa-list'></i> Role Definition</div>
                        </span>
                        <span class='col-lg-3 text-right actions'>
                            <button type="button" disabled="" id='role_edit_btn' class='btn btn-info btn-sm'><i class='fa fa-pencil'></i> Edit</button>
                            <button type="button" disabled="" id='role_del_btn' class="btn btn-danger btn-sm"><i class='fa fa-minus'></i> Delete</button>
                        </span>
                    </div>
                </div>
                <div class='panel-body'>
                    <div class="panel-group m-b" id="accordion2">
                        <form id='role_data_form' action='<?php echo $this->here; ?>' method='post' class="form-horizontal">
                            <div class="form-group">
                                <div class="control-label col-lg-3">Name: </div>
                                <div class="control-group col-lg-9">
                                    <input type="text" disabled="" id='role_name' name='role_name' required='' class="form-control input-sm input-s-lg" placeholder="Enter Role Name" />
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="control-label col-lg-3">Admin Access: </div>
                                <div class="control-group col-lg-9">
                                    <div class="row">
                                        <div class="col-lg-1">
                                            <input type="checkbox" disabled="" id='admin_access' name='admin_access'  class="" />
                                        </div>

                                        <div class="col-lg-11">
                                            This role has access to admin functionality to edit organisation settings, create accounts and more.
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="control-label col-lg-3">Module Access:</div>
                                <div class="controls col-lg-9">
                                    <ul style='list-style: none; padding: 0px;'>
                                        <?php
                                        $i = 0;
                                        foreach ($modules as $module) {
                                            echo "<li class='module_li'>";
                                            echo "<label class='font-normal'>";
                                            echo "<input class='module_checkbox' type='checkbox' disabled='' name='module[{$i}][module_id]' value='{$module['Module']['id']}' /> ";
                                            echo "<input class='role_id' type='hidden' name='module[{$i}][role_id]' value='' /> ";
                                            echo "<input class='id' type='hidden' name='module[{$i}][id]' value='' /> ";
                                            echo "<span>{$module['Module']['name']}</span>";
                                            echo "</label>";

                                            $x = 0;
                                            echo "<ul style='list-style: none;'>";
                                            foreach ($module['ModuleMenu'] as $menu) {

                                                echo "<li>";
                                                echo "<label class='font-normal'>";
                                                echo "<input class='menu_checkbox' type='checkbox' disabled='' name='module[{$i}][module_menu_ids][$x]' value='{$menu['id']}' /> ";
                                                echo "<span>{$menu['display_name']}</span>";
                                                echo "</label>";
                                                echo "</li>";
                                                $x++;
                                            }
                                            echo "</ul>";
                                            echo "</li>";

                                            $i++;
                                        }
                                        ?>
                                    </ul>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-lg-9 col-lg-offset-3">
                                    <input type='hidden' class='role_id' name='role_id' value='' />
                                    <button type="submit" disabled="" id='save_btn' class="btn btn-sm btn-success">Save Changes</button>
                                    <button type="button" disabled="" id='cancel_btn' class="btn btn-sm btn-white">Cancel</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>


<input type='hidden' id='role_data_url' value='<?php echo $this->Html->url(array('controller' => 'settings', 'action' => 'role')); ?>' />

<?php
echo $this->Html->script('plugins/jquery.trocar/jquery.trocar.js');
echo $this->Html->script('app/views/settings/accounts.js');
?>
